<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/5/27 0027
 * Time: 9:55
 */

namespace app\admin\controller;


use think\Db;
use think\Session;

class Login extends Base
{
    //todo 登录
    public function Login(){
        $map = ['account'=>$this->data['account'],'password'=>md5($this->data['password'])];
        $admin = Db::name('admin')->where($map)->find();
        if(!$admin)return $this->returnError('该管理员不存在');
        if($admin['status'] == 2)return $this->returnError('管理员状态异常,无法登陆');
        $auth = ['aid'=>$admin['aid'],'expire'=>time()+3600,'account'=>$admin['account']];
        Session::set('auth',$auth);
        Db::name('admin')->update(['aid'=>$admin['aid'],'log_time'=>time()]);
        return $this->returnSuccess('登录成功');
    }

    public function LoginOut(){
        Session::set('auth',null);
        return $this->returnSuccess('登录已注销');
    }


}